package com.example.shaoying.yuejian.fragment.mainFragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.shaoying.yuejian.R;
import com.example.shaoying.yuejian.adapter.GameAdapter;
import com.example.shaoying.yuejian.javabean.Game;
import com.example.shaoying.yuejian.model.ActivityModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class GameFragment extends Fragment {
    private View view;
    RecyclerView recyclerView;
    List<Game> data;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.game, container, false);
        initView();

        initData();
        return view;
    }

    private void initView() {
        recyclerView = (RecyclerView) view.findViewById(R.id.L_game);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    }

    private void initData() {
        ActivityModel model = new ActivityModel();
        Call<List<Game>> call = model.getlistsGame();
        call.enqueue(new Callback<List<Game>>() {
            @Override
            public void onResponse(Call<List<Game>> call, Response<List<Game>> response) {
                data = response.body();
                recyclerView.setAdapter(new GameAdapter(getActivity(), data));
            }

            @Override
            public void onFailure(Call<List<Game>> call, Throwable t) {

            }
        });
    }
}